package com.magnificent.atlantis.client.data.task;

import com.magnificent.atlantis.client.data.task.planner.AbstractPlannerTask;
import com.magnificent.atlantis.client.ui.planner.PlannerData;
import com.magnificent.commons.utils.DateUtils;

import java.util.Date;

/**
 * User: Babanin
 * Date: 08.08.2009
 * Time: 1:05:19
 */
public class TaskFilter {
    private Date endDate;
    private Date startDate;

    private boolean showActiveTasks;
    private boolean showFinishedTasks;

    public TaskFilter(PlannerData plannerData) {
        startDate = DateUtils.midnight(new Date());
        endDate = DateUtils.midnight(DateUtils.nextDay(startDate));

        showActiveTasks = plannerData.getSettingsContainer().isShowActiveTasks();
        showFinishedTasks = plannerData.getSettingsContainer().isShowFinishedTasks();
    }

    public boolean isOk(AbstractPlannerTask task) {
        if (!DateUtils.between(startDate, task.getStartDate(), endDate)) {
            return false;
        }

        if (task.isFinished()) {
            return showFinishedTasks;
        } else {
            return showActiveTasks;
        }
    }

    public Date getEndDate() {
        return endDate;
    }

    public void setEndDate(Date endDate) {
        this.endDate = endDate;
    }

    public boolean isShowActiveTasks() {
        return showActiveTasks;
    }

    public void setShowActiveTasks(boolean showActiveTasks) {
        this.showActiveTasks = showActiveTasks;
    }

    public boolean isShowFinishedTasks() {
        return showFinishedTasks;
    }

    public void setShowFinishedTasks(boolean showFinishedTasks) {
        this.showFinishedTasks = showFinishedTasks;
    }

    public Date getStartDate() {
        return startDate;
    }

    public void setStartDate(Date startDate) {
        this.startDate = startDate;
    }
}

